﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using TotalApplication.services;

namespace TotalApplication.C__Comic.fileStream
{
    /// <summary>
    /// AplyWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AplyWindow : Window
    {
        public AplyWindow()
        {
            InitializeComponent();
        }


        private void Button_Click1(object sender, RoutedEventArgs e)
        {
            FileInfo fileInfo = new FileInfo(@"C:\Users\admin\Desktop\test.txt");
            if ((fileInfo.Exists))
            {
                MessageBox.Show("It's exist");
            }
            else
            {
                fileInfo.Create().Close();
            }

            var dir = Directory.GetCurrentDirectory();
            MessageBox.Show(dir);
        }

        private void Button_Click2(object sender, RoutedEventArgs e)
        {
            FileInfo fileInfo = new FileInfo(@"C:\Users\admin\Desktop\test.txt");
            using (FileStream fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                byte[] buffer = new byte[1024];
                int bytesRead = fileStream.Read(buffer, 0, buffer.Length);
                string content = Encoding.UTF8.GetString(buffer, 0, bytesRead);

                MessageBox.Show(content);
            }
        }

        private void Button_Click3(object sender, RoutedEventArgs e)
        {
            FileInfo fileInfo = new FileInfo(@"C:\Users\admin\Desktop\test.txt");
            StringBuilder contentBuilder = new StringBuilder();
            foreach(var line in File.ReadLines(fileInfo.FullName))
            {
                contentBuilder.AppendLine(line);
            }
            MessageBox.Show(contentBuilder.ToString());
        }
    }
}
